package controller

import (
	"fmt"
	sessionStore "github.com/test/src/github.com/http/session-store"
	"net/http"
)

// 登录
func LoginHandle(writer http.ResponseWriter, request *http.Request) {
	request.ParseForm()
	username := request.FormValue("username")
	sessionId := "sessionId_" + username
	currentSessionInfo := sessionStore.SessionInfo{
		SessionId: sessionId,
		Username:  username,
	}
	sessionStore.SessionMap[sessionId] = currentSessionInfo
	cookie := http.Cookie{
		Name:     sessionStore.COOKIE_SESSION_ID,
		Value:    sessionId,
		HttpOnly: true,
	}
	http.SetCookie(writer, &cookie)
	fmt.Fprintf(writer, "hi,%s", username)
}
